package com.gouaixin.bee.beeframework2.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.WindowManager;
import android.widget.TextView;

import com.gouaixin.bee.beeframework2.MyApplication;
import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.tool.PreferencesUtils;

/**
 * Created by Administrator on 2015/4/27.
 */
//充值成功，跳转到的送话费页面
public class paySuccessActivity2 extends FragmentActivity{
    Context context=paySuccessActivity2.this;


    private WindowManager wm=null;
    private WindowManager.LayoutParams wmParams=null;

    public  TextView myFV=null;
    int payAmount;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.paysuccess);

        initIntent();



//        createView();

        initPayAmount();
    }

    private void initIntent() {
        Intent it=getIntent();
        payAmount=it.getIntExtra("amount",0);

    }

    private void initPayAmount() {
        payAmount= PreferencesUtils.getInt(context, "payAmount", 0);
        Log.e("test","paySuccessActivity:获取的已充值金额="+payAmount);
        int giftAmount=2*payAmount;
        String str=getResources().getString(R.string.chonghuafei);
        str=str.replace("XXX",payAmount+"");
        str=str.replace("YYY",giftAmount+"");
        Log.e("test","paySuccessActivity:str="+str);

//        TextView tv= (TextView) findViewById(R.id.tv);
//
//        if(payAmount!=0){
//            tv.setText(str);
//        }


    }


    private void createView(){
        myFV= (TextView) LayoutInflater.from(context).inflate(R.layout.head_chonghuafei,null);
        Log.e("test","myFV.getHeight()="+myFV.getHeight());

        //获取WindowManager
        wm=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
        //设置LayoutParams(全局变量）相关参数
        wmParams = ((MyApplication)getApplication()).getMywmParams();

        /**
         *以下都是WindowManager.LayoutParams的相关属性
         * 具体用途可参考SDK文档
         */
        wmParams.type= WindowManager.LayoutParams.TYPE_PHONE;   //设置window type
        wmParams.format=PixelFormat.RGBA_8888;   //设置图片格式，效果为背景透明

        //设置Window flag
        wmParams.flags= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        /*
         * 下面的flags属性的效果形同“锁定”。
         * 悬浮窗不可触摸，不接受任何事件,同时不影响后面的事件响应。
         wmParams.flags=LayoutParams.FLAG_NOT_TOUCH_MODAL
                               | LayoutParams.FLAG_NOT_FOCUSABLE
                               | LayoutParams.FLAG_NOT_TOUCHABLE;
        */


        wmParams.gravity=Gravity.LEFT|Gravity.TOP;   //调整悬浮窗口至左上角
        //以屏幕左上角为原点，设置x、y初始值
        wmParams.x=0;
        wmParams.y=0;

        //设置悬浮窗口长宽数据
        wmParams.width=wm.getDefaultDisplay().getWidth();

        wmParams.height=120;






    }




}
